<?php

/**
 * @author NgAnh
 * @copyright 2013
 */
class Validationmodel extends CI_Model {
    var $validation_id;
    var $infor_id;
    var $value;
    var $note;
    var $is_deleted;
    var $created_by_user_id;
    var $created_on_date;
    var $last_modified_by_user_id;
    var $last_modified_on_date;
    
    function __construct()
    {
        // Call the Model constructor
        $this->load->database();
    }
    function get_validation($val_id){
        $query = $this->db->get_where('sur_validation',array('validation_id'=>$val_id,'is_deleted'=>false));
        return $query->result_array(); 
    }
    
    function validation_infor($inforid, $val_id,$val,$not,$userid,$date){
        $data=array(
            'validation_id' => $val_id,
            'infor_id' => $inforid,
            'value' => $val,
            'note' => $not,
            'is_deleted' => false,
            'created_by_user_id' => $userid,
            'created_on_date' => $date,
        );
        //$this->db->where('infor_id', $inforid);
        $this->db->insert('sur_validation', $data);
    }

    
    function get_validation_list($sid,$facul){
        $query = $this->db->query("SELECT infor.*, validation.value, validation.created_by_user_id, validation.note, validation.validation_id 
                        From sur_validation as validation, sur_infor as infor, sur_class as class, sur_trade as trade, sur_faculty as faculty 
                        WHERE validation.infor_id = infor.infor_id and infor.class_id = class.class_id and class.trade_id = trade.trade_id 
                        and trade.faculty_id = faculty.faculty_id and infor.survey_id = '".$sid."' and faculty.faculty_id = '".$facul."' 
                        and infor.is_deleted = 'False' ");
        return $query;
    }
    
    //insert all data foreach list
    function insert_infor($inforid,$val_id,$userid,$date){
        $data=array(
            'validation_id' => $val_id,
            'infor_id' => $inforid,
            'is_deleted' => false,
            'created_by_user_id' => $userid,
            'created_on_date' => $date,
        );
        //$this->db->where('infor_id', $inforid);
        $this->db->insert('sur_validation', $data);
    }
    //validation
    function update_validation($vali_id,$valu,$note,$userid,$date){
        $data=array(
            'value'=>$valu,
            'note'=>$note,
            'is_deleted' => false,
            'created_by_user_id' => $userid,
            'created_on_date' => $date,
        );
        $this->db->where('validation_id', $vali_id);
        $this->db->update('sur_validation', $data);
    }
    
        
}


?>